<template>
  <div class="geshou">
    <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
      <template v-for="(item, index) in firstlist">
        <router-link
          :to="{path:'/geshou/singerdetail/id',
        query:{id:item.id,title:item.name}}"
        >
          <div class="singer">
              <span class="head">
                <img :src="item.picUrl" alt />
              </span>
              <span class="name">{{item.name}}</span>
              <span class="count">-&nbsp;共{{item.albumSize}}首</span>
          </div>
        </router-link>
      </template>
    </van-list>
  </div>
</template>

<script>
import send from "../navshow";
export default {
  data() {
    return {
      singerlist: [], //其他全部歌手
      firstlist: [], //华语男歌手
      loading: false,
      finished: false
    };
  },
  created() {
    // 隐藏导航栏
    send.$emit("tab-show", true);

    // 显示播放器
    this.$store.commit("showplayer", true);

    this.axios.get("http://localhost:3000/artist/list?cat=1001&limit=100").then(res => {
      this.singerlist = res.data.artists;
      this.firstlist = res.data.artists.slice(0, 10);
    });
  },
  methods: {
    onLoad() {
      // 异步更新数据
      setTimeout(() => {
        for (let i = 0; i < 10; i++) {
          this.firstlist.push(this.singerlist[this.firstlist.length + 1]);
        }

        // 加载状态结束
        this.loading = false;

        // 数据全部加载完成
        if (this.firstlist.length >= 90) {
          this.finished = true;
        }
      }, 1000);
    }
  }
};
</script>

<style>
.geshou {
  margin-top: 80px;
}

.geshou .singer {
  display: flex;
  width: 100vw;
  height: 60px;
  align-items: center;
  margin-top: 15px;
  margin-bottom: 5px;
}

.geshou .head {
  display: block;
  width: 50px;
  height: 50px;
  margin-left: 20px;
}

.geshou .singer span {
  font-size: 16px;
}

.geshou .head img {
  width: 55px;
  height: 55px;
  border-radius: 50%;
}

.geshou .singer .name {
  margin-left: 20px;
  margin-right: 10px;
  color: #222831;
}

.geshou .singer .count {
  color: gray;
  font-size: 10px;
}

</style>
